using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

using SypEngine.Middleware;
using SypEngine.Garbage;
using SypEngine.SiteConfig;

namespace SypServer.SypEngine.SiteConfig
{
    public class SypSyncHandler : SypObject
    {
        public Hashtable SiteSyncList = null;
        
        public SypSyncHandler(SetText OutputMethod)
            : base(OutputMethod)
        {
        }

        public void AddSypPage(int SiteId, SypPage myPage)
        {
            if (SiteSyncList == null)
                SiteSyncList = new Hashtable();

            if (!SiteSyncList.ContainsKey(SiteId))
                SiteSyncList.Add(SiteId, new Queue<SypPage>());

            Queue<SypPage> SitePage = (Queue<SypPage>)SiteSyncList[SiteId];
            if (SitePage != null)
                SitePage.Add(myPage);
        }


        public void LocalSynchronise(int SiteId)
        {
            Queue<SypPage> SiteQueue = (Queue<SypPage>)SiteSyncList[SiteId];
            if (SiteQueue != null)
            {
                while (SiteQueue.Count != 0)
                {
                    SypPage myPage = SiteQueue.Dequeue();
                    myPage.GenerateXml();
                    free(myPage);
                }
            }
            else
                OutputMethod("No Sync queue for Site " + SiteId, Output.ERROR); 
        }

    }
}
